package com.neusoft.NursingHome.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.neusoft.NursingHome.po.LevelProject;
import com.neusoft.NursingHome.po.ResponseBean;
import com.neusoft.NursingHome.service.LevelProjectService;

@RestController
@RequestMapping("/levelproject")
public class LevelProjectController {

    @Autowired
    private LevelProjectService levelProjectService;

    /**
     * 获取指定护理级别下的所有护理项目 ID
     * @param levelId 护理级别 ID
     * @return 包含护理项目 ID 列表的 ResponseBean
     */
    @GetMapping("/projects/{levelId}")
    public ResponseBean<List<Integer>> getNursingProjectsByLevel(@PathVariable Integer levelId) {
        List<Integer> projectIds = levelProjectService.getNursingProjectsByLevel(levelId);
        return new ResponseBean<>(projectIds);
    }

    /**
     * 将护理项目添加到指定的护理级别
     * @param levelProject 包含护理级别 ID 和护理项目 ID 的 LevelProject 对象
     * @return 添加结果的 ResponseBean
     */
    @PostMapping("/add")
    public ResponseBean<Boolean> addProjectToLevel(@RequestBody LevelProject levelProject) {
        boolean result = levelProjectService.addProjectToLevel(levelProject);
        return new ResponseBean<>(result);
    }

    /**
     * 将指定护理级别下的护理项目移除
     * @param levelProject 包含护理级别 ID 和护理项目 ID 的 LevelProject 对象
     * @return 移除结果的 ResponseBean
     */
    @PostMapping("/remove")
    public ResponseBean<Boolean> removeProjectFromLevel(@RequestBody LevelProject levelProject) {
        boolean result = levelProjectService.removeProjectFromLevel(levelProject);
        return new ResponseBean<>(result);
    }

    /**
     * 按护理项目名称模糊搜索，并筛选出在指定护理级别下的护理项目
     * @param levelId 护理级别 ID
     * @param name 护理项目名称（支持模糊匹配）
     * @return 包含符合条件的 LevelProject 列表的 ResponseBean
     */
    @GetMapping("/searchnotin/{levelId}/{name}")
    public ResponseBean<List<LevelProject>> searchProjectsNotInLevel(
            @PathVariable Integer levelId,
            @PathVariable String name) {
        List<LevelProject> projects = levelProjectService.searchProjectsByName(levelId, name);
        return new ResponseBean<>(projects);
    }
}